package org.example.platform.beans.factory.Autoware;


import org.example.platform.beans.factory.Autoware.config.BeanDefinition;
import org.example.platform.beans.factory.Autoware.config.BeanReference;
import org.example.platform.beans.factory.Autoware.support.DefaultListableBeanFactory;
import org.example.platform.beans.factory.PropertyValue;
import org.example.platform.beans.factory.PropertyValues;
import org.example.platform.beans.factory.UserDao;
import org.example.platform.beans.simple.UserService;

/**
 * 注入属性和依赖对象
 */
public class Test3 {

    /**
     * 基于Cglib实线构造函数的类实例化策略
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        // 初始化BeanFactory
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        // userDao注册
        beanFactory.registerBeanDefinition("userDao", new BeanDefinition(UserDao.class));

        // UserService设置属性【uid、userDao】
        PropertyValues propertyValues = new PropertyValues();
        propertyValues.addPropertyValue(new PropertyValue("uId","10001"));
        propertyValues.addPropertyValue(new PropertyValue("userDao",new BeanReference("userDao")));

        // UserService注入bean
        BeanDefinition beanDefinition = new BeanDefinition(UserService.class,propertyValues);
        beanFactory.registerBeanDefinition("userService",beanDefinition);
        // 获取bean
        UserService userService = (UserService) beanFactory.getBean("userService");
        userService.queryUser();




    }
}
